// Dlgstopwork.cpp : implementation file
//

#include "stdafx.h"
#include "Dlgstopwork.h"
#include "../MotionControlSoftwareDoc.h"
#include "../MotionControlSoftwareView.h"
#include "../MainFrm.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDlgstopwork dialog

CDlgstopwork::CDlgstopwork(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgstopwork::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDlgstopwork)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}

void CDlgstopwork::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgstopwork)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlgstopwork, CDialog)
	//{{AFX_MSG_MAP(CDlgstopwork)
	ON_BN_CLICKED(IDSTOP, OnStop)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgstopwork message handlers

BOOL CDlgstopwork::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	CenterWindow(GetParent());
// 	GetDlgItem(IDSTOP)->SetWindowText(_T("ֹͣ"));
	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}

void CDlgstopwork::SetMotionCtrl(CMotionControl* pMotionCtrl)
{
	m_pMotionCtrl = pMotionCtrl;
}
void CDlgstopwork::SetStopType(int iStopType)
{
	m_stopType = iStopType;
}

int CDlgstopwork::GetStopType()
{
	return m_stopType;
}

void CDlgstopwork::SetJczCtrl(CMyJcz* pJcz)
{
	m_pJcz = pJcz;
}

void CDlgstopwork::OnStop() 
{
	// TODO: Add your control notification handler code here
	CMotionControlSoftwareDoc* m_pDoc = NULL;
	CMainFrame* pMainFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
	if (pMainFrame != NULL)
	{
		CMDIChildWnd* pMDIChild = pMainFrame->MDIGetActive();
		if (pMDIChild != NULL)
		{
			CMotionControlSoftwareView* pMainView = (CMotionControlSoftwareView*)(pMDIChild->GetActiveView());
			m_pDoc = (CMotionControlSoftwareDoc*)(pMainView->GetDocument());
		}
	}
	if (m_pDoc != NULL)
	{
		m_pDoc->StopWork(0);
		ShowWindow(SW_HIDE);
	}
}

BOOL CDlgstopwork::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	if (pMsg->message == WM_KEYDOWN)
	{
		TCHAR nChar = (TCHAR) (pMsg->wParam);
		if (nChar == VK_ESCAPE)
		{
			return TRUE;
		}
		else if(nChar == VK_RETURN)
		{
			return TRUE;
		}
		else if (nChar == VK_SPACE)
		{
			return TRUE;
		}
	}
	return CDialog::PreTranslateMessage(pMsg);
}
